import {
	defineStore
} from 'pinia'

export const runderStore = defineStore('runder', {
	state: () => ({
		nameData: "",
		statusData: false,
		progressData: 0,
		currentData: -1,
		runTypeData: "",
		infoData: {}
	}),
	getters: {
		isRun(state) {
			return state.statusData;
		},
		info(state) {
			return state.infoData;
		},
		progress(state) {
			return state.progressData;
		},
		current(state) {
			return state.currentData;
		},
		name(state) {
			return state.nameData;
		},
		runType(state) {
			return state.runTypeData
		}
	},
	actions: {
		initData() {
			this.nameData = ""
			this.statusData = false
			this.progressData = 0
			this.currentData = -1
			this.runTypeData = ""
			this.infoData = {}
		},
		setRun(status) {
			this.statusData = status;
		},
		setInfo(data) {
			this.infoData = data;
		},
		setProgress(data) {
			if (data < 0 || data > 100) return;
			this.progressData = data;
		},
		setCurrent(data) {
			this.currentData = data;
		},
		setName(data) {
			this.nameData = data;
		},
		setRunType(data) {
			this.runTypeData = data;
		},
	
	}
})

export const userStore = defineStore('user', {
	state: () => ({
		user: {},
	}),
	getters: {
		info(state) {
			return state.user;
		}
	},
	actions: {
		setUser(data) {
			this.user = data
		},
		logout() {
			this.user = {}
		}
	}
})



export const settingStore = defineStore('setting', {
	state: () => ({
		configData: {
			sound: true,
			print: true,
			brightnes: 0.5,
			statusBarHeight: 0,
			windowHeight: 0
		},
		roleData: [{
			id: 1,
			name: "普通用户"
		}, {
			id: 2,
			name: "管理员"
		}, {
			id: 4,
			name: "工程师"
		}],

		// let p = 0b001
		// let a = 0b010
		// let g = 0b100

		// let p = 1 //普通
		// let a = 2 //管理
		// let g = 4 //工程

		// let perm = a | g

		// function include(premission, permBit) {
		// 	return (premission & Number(permBit)) === permBit;
		// }
		// console.log('权限', perm, p, include(perm, p))

		//特殊设置
		specialData: [],
		//参数设置
		paramsData: [],
	}),
	getters: {
		config(state) {
			return state.configData;
		},
		role(state) {
			return state.roleData
		},
		special(state) {
			return state.specialData
		},
		params(state) {
			return state.paramsData
		}
	},
	actions: {
		setConfig(key, data) {
			this.configData[key] = data
		},
		setSpecial(data) {
			this.specialData = data
		},
		setParams(key, data) {
			this.paramsData[key] = data
		}
	}
})